package com.propic.www;

import com.sun.javafx.tk.Toolkit;
import javafx.application.Application;
import javafx.collections.MapChangeListener;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Screen;
import javafx.stage.Stage;

public class OpensinglePhoto extends Application{
//	public static Stage stage = new Stage();
//	public static StackPane pane = new StackPane();
	public static Scene showPhoto(Image image, Stage stage) {
//		StackPane pane = new StackPane();
		BorderPane Bpane = new BorderPane();

		System.out.println(image.toString());
		ImageView showpicture = new ImageView(image);
		
//		pane.setStyle("-fx-background-color:#272a40");
//		pane.setMaxSize(720,444);
//		pane.setMinSize(720,444);

//		pane.getChildren().add(showpicture);
        Bpane.setCenter(showpicture);

		//边距大小
		int borderPic = 30;
		//弹出窗口大小
		Scene scene = new Scene(Bpane, 1000, 618);
		scene.setOnMouseClicked((MouseEvent t)->{
			MouseButton button = t.getButton();
			switch (button) {
			case SECONDARY:
				if(t.getClickCount()==2){
					stage.close();
				}
				break;
			case PRIMARY:
				if (t.getClickCount() == 2 && stage.isFullScreen()) {
					stage.setFullScreen(false);
                    stage.setScene(scene);
                    if(!stage.isFullScreen())
                        System.out.println("decrease"+Bpane.getHeight()+"  "+Bpane.getWidth()+" ");
//                    System.out.println("decrease"+pane.getHeight()+"  "+pane.getWidth());
//                    System.out.println()
				}else if(t.getClickCount() == 2 && !stage.isFullScreen()){

					stage.setFullScreen(true);
                    stage.setScene(scene);
                    if(stage.isFullScreen())
                        System.out.println("enlarge"+Bpane.getHeight()+"  "+Bpane.getWidth());

				}
			default:
				break;
			}
		});


        if (image.getHeight()/image.getWidth()>0.62) {
            showpicture.setFitHeight(Bpane.getHeight()-borderPic);
            showpicture.setFitWidth(((Bpane.getHeight()-borderPic)/image.getHeight())*image.getWidth());
        }else{
            showpicture.setFitHeight(((Bpane.getWidth()-borderPic)/image.getWidth())*image.getHeight());
            showpicture.setFitWidth(Bpane.getWidth()-borderPic);
        }
		return scene;
	}
	@Override
	public void start(Stage arg0) throws Exception {
		// TODO Auto-generated method stub
		
	}
}
